package com.ad.pet.app.recharge;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.data.injector.PerActivity;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.CommList;
import com.ad.pet.models.remote.recharge.Alipay;
import com.ad.pet.models.remote.recharge.Recharge;
import com.ad.pet.models.remote.recharge.Weixin;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by SEELE on 2018/6/5.
 */
@PerActivity
public class RechargePresenter extends AbsBasePresenter implements RechargeContract.Presenter{

    private ApiService mApiService;
    private RechargeContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public RechargePresenter(ApiService apiService,
                           Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }

    @Override
    public void onDestroy() {
        if (mRxDisposable != null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }

    @Override
    public void onCreate(RechargeContract.View view) {
        this.mView = view;
    }



    @Override
    public void getPayChannal() {
        mRxDisposable.add(mApiService.get_channel_list()
                .subscribe(new AppSubscriber<CommList<List<Recharge>>>(mView) {
                    @Override
                    public void next(CommList<List<Recharge>> keyWord) {
                        mView.getPayChannalSuccess(keyWord);
                    }
                }));
    }

    @Override
    public void get_pay_wx(String value, String type) {
        mRxDisposable.add(mApiService.get_pay_wx(value,type)
                .subscribe(new AppSubscriber<Weixin>(mView) {
                    @Override
                    public void next(Weixin keyWord) {
                        mView.get_pay_wx(keyWord);
                    }
                }));
    }

    @Override
    public void get_pay_alipay(String value, String type) {
        mRxDisposable.add(mApiService.get_pay_alipay(value,type)
                .subscribe(new AppSubscriber<Alipay>(mView) {
                    @Override
                    public void next(Alipay keyWord) {
                        mView.get_pay_alipay(keyWord);
                    }
                }));
    }
}
